package com.gt.sql

import com.gt.SCUtil
import org.apache.spark.sql.{DataFrame, SparkSession}

object SparkDataFrame_01 {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SCUtil.buildLocalSparkSession()
    val df: DataFrame = spark.read.json("data/user.json")

    df.show(10,false)
    df.printSchema()

    df.createOrReplaceTempView("user")
    val df2: DataFrame = spark.sql("select name from user")
    df2.show()
    df2.printSchema()

    val df3: DataFrame = spark.sql("select avg(age) from user")
    df3.show()
    df3.printSchema()



    spark.close()
  }

}
